// 对购物车进行渲染
export default function(){
    function cartRnder(){

    }
    $.extend(cartRnder.prototype,{
        init : function(res){
            this.load_pic = $(".cart-list");
            var ls  = localStorage.getItem("goods");
            if( ls !== null && ls !== "[]"){
                $(this.load_pic)[0].style.display = "none";
                return this.renderCartList(res , ls);
            }
        },
        renderCartList : function(res , ls){
            var la = JSON.parse(ls);
            res = res.filter(function(goods_item){
                return la.some(function(carts_item){
                      if(carts_item.id == goods_item.goods_id){
                            goods_item.count = carts_item.count;
                            return true;
                      };
                }) 
            })
            var render_html = "";
            $.each(res,function(index,item){
                render_html += `<div class="detail-list-top">
                            <div class="detail-list-top-content">
                                <img class="pic-target" src="http://s2.juancdn.com/bao/170615/2/b/5942339ea43d1f47ef70e59a_72x72.png" alt="">
                                跨店促销
                            </div>
                            <a href="" class="goods-activity">${item.m}&nbsp;去凑单 >></a>
                            </div>
                            <div class="detail-list-content">
                                <div class="content_1"></div>
                                    <a href="./detail.html#${item.goods_id}">
                                        <img class="goods-pic-s" src="${item.left_pic_1}" alt="">
                                    </a>
                                <div class="goods-describe">
                                    <strong class="goods-name">${item.title}</strong>
                                </div>
                                <div class="goods-all-price">
                                    ￥${item.cprice}
                                    <i class="goods-yuanjia">/￥${item.oprice}</i>
                                </div>
                                <div class="goods-total-count" data-id="${item.goods_id}">
                                    <span class="left-down">-</span>
                                    <span class="middle-content_1">${item.count}</span>
                                    <span class="right-up">+</span>
                            </div>
                            <div class="goods-total-price">
                                ￥${item.count * item.cprice}
                            </div>
                            <div class="goods-del" data-id="${item.goods_id}">
                                <span class="del-btn" ></span>
                            </div>
                        </div>
                        <div class="bottom-content">
                            <div class="nothing-show"></div>
                            <div class="goods-settlement">
                                已选择
                                <span class="choosed">${item.count}</span>
                                件,合计
                                <span class="all-goods-price">￥${item.count * item.cprice}</span>
                                <button class="settlement-btn">去结算</button>
                            </div>
                        </div> `
            })
            return render_html;
        }
    })
    return new cartRnder();
}